package com.mf.ergate.controller.wx;

import com.alibaba.fastjson.JSONObject;
import com.mf.ergate.api.wx.WeixinRemoteService;
import com.mf.ergate.service.wx.WeixinService;
import com.mf.framework.common.model.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 微信相关Controller
 * User: zhaoming
 * DateTime: 2019-04-16
 * To change this template use File | Settings | File Templates.
 */
@RestController
public class WeixinController implements WeixinRemoteService {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private WeixinService weixinService;

    /**
     * 登录凭证校验
     * @param code 登录时获取的code
     * @return openid
     */
    public Result<String> code2Session(@RequestParam String code) {
        JSONObject jsonObject = weixinService.code2Session(code);
        return new Result<>(jsonObject.getString("openid"));
    }

}